home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / BCCollec / Support / BCExcept.h < prev    next >
Encoding:
Text File  |  1994-04-21  |  6.0 KB  |  248 lines  |  [TEXT/MPS ]

  1. //  The C++ Booch Components (Version 2.1)
  2. //  (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
  3. //
  4. //  BCExcept.h
  5. //
  6. //  This file contains the declaration of the classes and functions
  7. //  associated with exception handling.
  8.  
  9. #ifndef BCEXCEPT_H 
  10. #define BCEXCEPT_H 1 
  11.  
  12. #include "BCType.h"
  13.  
  14. // Patch to use the OPF foundation debug facilities
  15. #ifndef FWPRIDEB_H
  16. #include "FWPriDeb.h"
  17. #endif
  18.  
  19. // [KVV] To share data in Windows accross DLLs, we need to declare it with __far
  20. #ifdef FW_BUILD_MAC
  21. #define BC_SHARED_DATA
  22. #endif
  23.  
  24. #if defined(FW_BUILD_WIN)
  25. #if defined(FW_BUILD_WIN32S) || defined(FW_BUILD_WINNT)
  26. #define BC_SHARED_DATA
  27. #else
  28. #define BC_SHARED_DATA __far
  29. #endif
  30. #endif
  31.  
  32. //========================================================================================
  33. // BC_CAN_EXPORT_DATA
  34. //========================================================================================
  35.  
  36. #if defined(FW_BUILD_MAC) || defined(FW_BUILD_WIN16)
  37. #define BC_CAN_EXPORT_DATA
  38. #endif
  39.  
  40. #ifdef BC_CAN_EXPORT_DATA
  41. extern const char* BC_SHARED_DATA BC_kDisjoint;
  42. extern const char* BC_SHARED_DATA BC_kDuplicate;
  43. extern const char* BC_SHARED_DATA BC_kEmpty;
  44. extern const char* BC_SHARED_DATA BC_kFull;
  45. extern const char* BC_SHARED_DATA BC_kIllegal;
  46. extern const char* BC_SHARED_DATA BC_kInvalidIndex;
  47. extern const char* BC_SHARED_DATA BC_kInvalidNumber;
  48. extern const char* BC_SHARED_DATA BC_kMissing;
  49. extern const char* BC_SHARED_DATA BC_kNotEmpty;
  50. extern const char* BC_SHARED_DATA BC_kNotRoot;
  51. extern const char* BC_SHARED_DATA BC_kNull;
  52. extern const char* BC_SHARED_DATA BC_kOutOfMemory;
  53. extern const char* BC_SHARED_DATA BC_kReferenced;
  54. extern const char* BC_SHARED_DATA BC_kTooLarge;
  55. extern const char* BC_SHARED_DATA BC_kTooSmall;
  56. #else
  57. const char* BC_Get_kDisjoint();
  58. #define BC_kDisjoint            BC_Get_kDisjoint()
  59. const char* BC_Get_kDuplicate();
  60. #define BC_kDuplicate         BC_Get_kDuplicate()
  61. const char* BC_Get_kEmpty();
  62. #define BC_kEmpty                    BC_Get_kEmpty()
  63. const char* BC_Get_kFull();
  64. #define BC_kFull                    BC_Get_kFull()
  65. const char* BC_Get_kIllegal();
  66. #define BC_kIllegal                BC_Get_kIllegal()
  67. const char* BC_Get_kInvalidIndex();
  68. #define BC_kInvalidIndex    BC_Get_kInvalidIndex()
  69. const char* BC_Get_kInvalidNumber();
  70. #define BC_kInvalidNumber    BC_Get_kInvalidNumber()
  71. const char* BC_Get_kMissing();
  72. #define BC_kMissing                BC_Get_kMissing()
  73. const char* BC_Get_kNotEmpty();
  74. #define BC_kNotEmpty            BC_Get_kNotEmpty()
  75. const char* BC_Get_kNotRoot();
  76. #define BC_kNotRoot                BC_Get_kNotRoot()
  77. const char* BC_Get_kNull();
  78. #define BC_kNull                    BC_Get_kNull()
  79. const char* BC_Get_kOutOfMemory();
  80. #define BC_kOutOfMemory        BC_Get_kOutOfMemory()
  81. const char* BC_Get_kReferenced();
  82. #define BC_kReferenced        BC_Get_kReferenced()
  83. const char* BC_Get_kTooLarge();
  84. #define BC_kTooLarge            BC_Get_kTooLarge()
  85. const char* BC_Get_kTooSmall();
  86. #define BC_kTooSmall            BC_Get_kTooSmall()
  87. #endif
  88.  
  89. // Exception base class
  90.  
  91. class BC_XException {
  92. public:
  93.  
  94.   BC_XException(const char* name, const char* who, const char* what);
  95.   
  96.   void Display() const;
  97.  
  98.   const char* Name() const
  99.     {return fName;}
  100.   const char* Who() const 
  101.     {return fWho;}
  102.   const char* What() const 
  103.     {return fWhat;}
  104.   
  105. protected:
  106.  
  107.   enum {BC_MAXIMUM_LENGTH = 63};
  108.  
  109.   char fName[BC_MAXIMUM_LENGTH + 1];
  110.   char fWho [BC_MAXIMUM_LENGTH + 1];
  111.   char fWhat[BC_MAXIMUM_LENGTH + 1];
  112.  
  113. };
  114.  
  115. // Predefined global exceptions
  116.  
  117. class BC_XContainerError : public BC_XException {
  118. public:
  119.  
  120.   BC_XContainerError(const char* who, const char* what)
  121.     : BC_XException("Container_Error", who, what) {}
  122.  
  123. };
  124.  
  125. class BC_XDuplicate : public BC_XException {
  126. public:
  127.  
  128.   BC_XDuplicate(const char* who, const char* what)
  129.     : BC_XException("Duplicate", who, what) {}
  130.  
  131. };
  132.  
  133. class BC_XIllegalPattern : public BC_XException {
  134. public:
  135.  
  136.   BC_XIllegalPattern(const char* who, const char* what)
  137.     : BC_XException("Illegal_Pattern", who, what) {}
  138.  
  139. };
  140.  
  141. class BC_XIsNull : public BC_XException {
  142. public:
  143.  
  144.   BC_XIsNull(const char* who, const char* what)
  145.     : BC_XException("Is_Null", who, what) {}
  146.  
  147. };
  148.  
  149. class BC_XLexicalError : public BC_XException {
  150. public:
  151.  
  152.   BC_XLexicalError(const char* who, const char* what)
  153.     : BC_XException("Lexical_Error", who, what) {}
  154.  
  155. };
  156.  
  157. class BC_XMathError : public BC_XException {
  158. public:
  159.  
  160.   BC_XMathError(const char* who, const char* what)
  161.     : BC_XException("Math_Error", who, what) {}
  162.    
  163. };
  164.  
  165. class BC_XNotFound : public BC_XException {
  166. public:
  167.  
  168.   BC_XNotFound(const char* who, const char* what)
  169.     : BC_XException("Not_Found", who, what) {}
  170.  
  171. };
  172.  
  173. class BC_XNotNull : public BC_XException {
  174. public:
  175.  
  176.   BC_XNotNull(const char* who, const char* what)
  177.     : BC_XException("Not_Null", who, what) {}
  178.  
  179. };
  180.  
  181. class BC_XNotRoot : public BC_XException {
  182. public:
  183.  
  184.   BC_XNotRoot(const char* who, const char* what)
  185.     : BC_XException("Not_Root",who, what) {}
  186.  
  187. };
  188.  
  189. class BC_XOverflow : public BC_XException {
  190. public:
  191.  
  192.   BC_XOverflow(const char* who, const char* what)
  193.     : BC_XException("Overflow", who, what) {}
  194.  
  195. };
  196.  
  197. class BC_XRangeError : public BC_XException {
  198. public:
  199.  
  200.   BC_XRangeError(const char* who, const char* what)
  201.     : BC_XException("Range_Error", who, what) {}
  202.  
  203. };
  204.  
  205. class BC_XStorageError : public BC_XException {
  206. public:
  207.  
  208.   BC_XStorageError(const char* who, const char* what)
  209.     : BC_XException("Storage_Error", who, what) {}
  210.  
  211. };
  212.  
  213. class BC_XUnderflow : public BC_XException {
  214. public:
  215.  
  216.   BC_XUnderflow(const char* who, const char* what)
  217.     : BC_XException("Underflow", who, what) {}
  218.  
  219. };
  220.  
  221. // Exception handler
  222.  
  223. extern void BC_Catch(const BC_XException&);
  224.  
  225. // Assertion function
  226.  
  227. //========================================================================================
  228. //
  229. // The following is a patch to the components so that they use the
  230. // OPF assertion mechanism.
  231.  
  232. #if defined(BC_DEBUG) && defined(FW_DEBUG)
  233. #define BC_Assert(expression, exception) FW_ASSERT(expression);
  234. #elif defined (BC_DEBUG)
  235. inline void BC_Assert(BC_Boolean expression, const BC_XException& exception)
  236. {
  237.   if (!expression)
  238.     throw(exception);
  239. }
  240. #else
  241. inline void BC_Assert(BC_Boolean, const BC_XException&) {}
  242. #endif
  243.  
  244. //
  245. //========================================================================================
  246.  
  247. #endif
  248.